﻿using System;
using System.Text;

public class BinaryRepresentationOfShortNumber
{
    public static void Main()
    {
        Console.WriteLine(BinaryRepresentationOfShort("Problem 8: Binary representation of 'short' number"));
    }

    private static string BinaryRepresentationOfShort(string startingDescription)
    {
        StringBuilder description = new StringBuilder(startingDescription.ToString());
        int number;
        string converted;

        do
        {
            if (int.TryParse(ConversionBetweenNumeralSystems.InputNumber(description.ToString(), 10), out number)
                && ((-32768 <= number) && (number <= 32767)))
                break;
        } while (true);

        description.Append("\n" + number + "(10) = ");
        if (number < 0)
        {
            description.Append("1");
            number += 32768;
        }
        else
            description.Append("0");

        converted = ConversionBetweenNumeralSystems.FromDecimalToNewSystem(number, 2);
        Console.Clear();
        return description.ToString() + new string('0', (15 - converted.Length)) + converted + "(short)";
    }
}